package com.well.register.console.controller;

import com.well.register.console.aop.WellException;
import com.well.register.console.domain.ServerModel;
import com.well.register.console.model.server.QueryRegisterServerParam;
import com.well.register.console.service.ServerService;
import com.well.register.console.util.RpcResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * register server controller
 * </p>
 *
 * @author weedo
 * @since 2022/8/10
 */

@RestController
@RequestMapping("well-server")
public class ServerController {

    @Resource
    private ServerService serverService;

    @PostMapping("list")
    public List<ServerModel> getRegisterServer(QueryRegisterServerParam param) {
        return serverService.registerServerModel(param);
    }

    @PostMapping("down")
    public RpcResponse<Object> serverDown(Integer id) throws WellException {
        serverService.serverDownGracefully(id);
        return RpcResponse.ok();
    }
}
